<template>
  <ul class="catagtory">
    <li
      :class="{ select: index === $store.state.navbar.currIndex }"
      v-for="(item, index) in $store.state.navbar.list"
      :key="item.id"
      @click="liClick(index)"
    >
      {{ item.name }}
    </li>
  </ul>
</template>
<script>
export default {
  created () {
    // 触发actions获取列表数据
    this.$store.dispatch('navbar/getList')
  },
  methods: {
    // navbar选项点击事件，传入了点击项的索引
    liClick (index) {
      this.$store.commit('navbar/SETCURRINDEX', index)
      // 触发调用newsList内的actions获取文章列表
      const id = this.$store.state.navbar.list[index].id
      this.$store.dispatch('newsList/getNews', id)
    }
  }
}
</script>
<style></style>
